﻿/*
 * Copyright (c) Seagull Consulting, Inc. All rights reserved. See License.txt in the project root for license information.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SeagullConsulting.MvcAjaxControls.Data.Models;
using SeagullConsulting.MvcAjaxControls.Data.Repository;

namespace SeagullConsulting.MvcAjaxControls.Web.UI.Controllers
{
    public class AjaxDropdownController : Controller
    {

        private StateRepository stateRepository;
        private CountryRepository countryRepository;
        private CityRepository cityRepository;

        public AjaxDropdownController()
        {
            stateRepository = new StateRepository();
            countryRepository = new CountryRepository();
            cityRepository = new CityRepository();
            ViewData["controller"] = typeof(AjaxDropdownController).Name;
        }

        //
        // GET: /AjaxDropdown/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult ListCities(int? Id, int parentVal)
        {
            IList<City> cities = cityRepository.List(parentVal).ToList();
            return Json(cities, JsonRequestBehavior.AllowGet);
        }

        public JsonResult ListCities2(int? Id)
        {
            IList<City> cities = cityRepository.List((int) Id).ToList();
            return Json(cities, JsonRequestBehavior.AllowGet);
        }
        public JsonResult ListStates(int? Id, int parentVal)
        {
            IList<State> states = stateRepository.List(parentVal).ToList();
            return Json(states, JsonRequestBehavior.AllowGet);
        }
        public JsonResult ListStates2(int? Id)
        {
            IList<State> states = stateRepository.List((int)Id).ToList();
            return Json(states, JsonRequestBehavior.AllowGet);
        }
        public JsonResult ListCountries(int? Id)
        {
            IList<Country> countries = countryRepository.List().ToList();
            return Json(countries, JsonRequestBehavior.AllowGet);
        }
    }
}
